var e = getApp(), t = require("./../../../utils/core.js");

Page({
    data: {
        close: 0,
        text: "",
        imgUrl: ""
    },
    onLoad: function(t) {
        this.setData({
            close: t.close,
            text: t.text,
            imgUrl: e.globalData.approot
        });
    },
    onShow: function() {
        var t = e.getCache("sysset").shopname;
        wx.setNavigationBarTitle({
            title: t || "提示"
        });
        

    },
    bind: function() {
        var e = this, t = setInterval(function() {
            wx.getSetting({
                success: function(n) {
              
					var r = getApp().getCache("userinfo");
                    r && (wx.reLaunch({
                        url: "/pages/index/index"
                    }), clearInterval(t), e.setData({
                        userInfo: r
                    }));
                }
            });
        }, 1e3);
    },
    bindGetUserInfo: function(n) {
        var i = e.getCache("routeData"), a = i.url, o = i.params, s = "";
        Object.keys(o).forEach(function(e) {
            s += e + "=" + o[e] + "&";
        });
        var c = "/" + a + "?" + (o = s.substring(0, s.length - 1));
        wx.getUserProfile({
            desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
            success: (res) => {
                wx.login({
                    success: function(i) {
                        t.post("wxapp/login", {
                            code: i.code
                        }, function(i) {
                            if(i.error){
                                t.alert("获取用户登录态失败:" + i.message)
                            }else{
                                t.get("wxapp/auth", {
                                    data: res.encryptedData,
                                    iv: res.iv,
                                    sessionKey: i.session_key,
                                    openId:i.openid
                                }, function(t) {
                                    console.log(t), 1 == t.isblack && wx.showModal({
                                        title: "无法访问",
                                        content: "您在商城的黑名单中，无权访问！",
                                        success: function(t) {
                                            t.confirm && e.close(), t.cancel && e.close();
                                        }
                                    }), 
                                    e.setCache("userinfo",t), e.setCache("userinfo_openid", t.openId), 
                                    e.setCache("userinfo_id", t.id), e.getSet(), wx.reLaunch({
                                        url: c
                                    });
                                });
                               
                                
                            }
                      
                        });
                    },
                    fail: function() {
                        t.alert("获取用户信息失败!");
                    }
                });
            },fail:function(err){
                console.log(err)
            }
          })
     
       
    },
    cancelLogin: function() {
        wx.switchTab({
            url: "/pages/index/index"
        });
    }
});